package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.constant.UserVideoConstant;
import com.juyu.miliao.api.domain.UserVideo;
import com.juyu.miliao.api.domain.vo.NightChatInTheSameCityVo;
import com.juyu.miliao.common.dataSource.tool.distributeOperate.DistributeOperate;
import com.juyu.miliao.common.dataSource.tool.operate.Operate;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 视频管理
 *
 * @author jh
 */
@Repository
public class UserVideoDao {

    @Resource
    private SqlSession sqlSession;

    @Operate("strategy('byVideoId',#videoId)")
    public int saveUserVideo(Long videoId, UserVideo userVideo) {
        return sqlSession.insert("saveUserVideo", userVideo);
    }

    @Operate("strategy('byVideoId',#videoId)")
    public int deleteUserVideo(Long userId, Long videoId) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("userId", userId);
        map.put("videoId", videoId);
        return sqlSession.delete("deleteUserVideo", map);
    }

    @Operate("strategy('byVideoId',#videoId)")
    public int findClickVideoLove(long userId, long videoId) {
        Map<String, Object> params = new HashMap<>();
        params.put("videoId", videoId);
        params.put("userId", userId);
        return sqlSession.selectOne("findClickVideoLove", params);
    }

    @Operate("strategy('byVideoId',#videoId)")
    public int deleteUserVideoLove(long userId, long videoId) {
        Map<String, Object> params = new HashMap<>();
        params.put("videoId", videoId);
        params.put("userId", userId);
        return sqlSession.delete("deleteUserVideoLove", params);
    }

    @Operate("strategy('byVideoId',#videoId)")
    public int addUserVideoLove(long userId, long videoId) {
        Map<String, Object> params = new HashMap<>();
        params.put("videoId", videoId);
        params.put("userId", userId);
        return sqlSession.insert("addUserVideoLove", params);
    }



    @DistributeOperate(ds = "miliao-user")
    public List<UserVideo> listUserVideoPass(Long userId, Integer offset, Integer pageSize) {
        Map<String, Object> map = new HashMap<>(8);
        map.put("userId", userId);
        map.put("offset", offset);
        map.put("pageSize", pageSize);
        return sqlSession.selectList("listUserVideoPass", map);
    }



    @DistributeOperate(ds = "miliao-user")
    public List<UserVideo> listUserVideoAll(Long userId, Integer offset, Integer pageSize) {
        Map<String, Object> map = new HashMap<>(8);
        map.put("userId", userId);
        map.put("offset", offset);
        map.put("pageSize", pageSize);
        return sqlSession.selectList("listUserVideoAll", map);
    }



    @DistributeOperate(ds = "miliao-user")
    public List<UserVideo> listUserVideoPageFree(Long userId, Integer startNum, Integer pageSize) {
        Map<String, Object> map = new HashMap<>(3);
        map.put("userId", userId);
        map.put("startNum", startNum);
        map.put("pageSize", pageSize);
        return sqlSession.selectList("listUserVideoPageFree", map);
    }
    
    @Operate("strategy('byVideoId',#videoId)")
	public int addCommentNum(Long videoId) {
		return sqlSession.update("addCommentNum", videoId);
	}

    @Operate("strategy('byVideoId',#videoId)")
	public int addLoveNum(long videoId) {
    	return sqlSession.update("addLoveNum", videoId);
	}

    @Operate("strategy('byVideoId',#videoId)")
	public int deleteLoveNum(long videoId) {
    	return sqlSession.update("deleteLoveNum", videoId);
	}

    /**
     * 查询同城夜聊列表
     * @param parameterMap
     */
    @DistributeOperate(ds = "miliao-user")
    public List<NightChatInTheSameCityVo> selectNightChatList(Map<String, Object> parameterMap) {
        return sqlSession.selectList("selectNightChatList",parameterMap);
    }

    @DistributeOperate(ds = "miliao-user")
    public List<NightChatInTheSameCityVo> selectNightChatByUserIdList(Map<String, Object> parameterMap) {

        return sqlSession.selectList("selectNightChatByUserIdList", parameterMap);
    }
    @Operate("strategy('byVideoId',#videoId)")
    public UserVideo selectByVideoId(long videoId) {
        return sqlSession.selectOne("selectByVideoId", videoId);
    }


}
